package uia.alumni.web;

import java.io.PrintWriter;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.persistence.Query;
import javax.servlet.http.HttpServletRequest;
import uia.alumni.data.User;



/**
 * This servlet outputs the application's start page.
 * @author Even Åby Larsen (even.larsen@uia.no)
 */
public class Home extends Page {
    public static final String SERVLET_NAME = "home";

    @PersistenceUnit(name=PERSISTENCE_UNIT)
    private EntityManagerFactory emf;


    public Home() {
        super(null);
    }


    /**
     * Write the html document. This method is called by format, and
     * is expected to write the html code for the main content div
     * to the the PrintWriter out.
     */
    public void writeBody(PrintWriter out, HttpServletRequest request) {
                        User user = (User)request.getSession().getAttribute(USER);


 if (user == null) {
        out.println("<html>");
out.println("<head>");
out.println("<meta http-equiv=\"refresh\" content=\"0;URL=start.do\">");
out.println("</head>");
out.println("</html>");
        }
        else {
         out.println("<!DOCTYPE html>");
 out.println("<html lang=en>");
 out.println("<head>");
 out.println(" <meta charset=utf-8>");
 out.println("<title>Profil</title>");
 out.println("</head>");
 out.println("<body>");
 out.println("<h1>Velkommen "+user.getFullName()+" </h1>");
 out.println("<p>Gå til <a href=\"profile.view.do\">din profil</a> eller <a href=\"profile.edit.do\">endre den</a> </p>");
 out.println("<p><a href=\"pms.pms.do\">Du har x nye meldinger i din innboks</a></p>");
 out.println("<p><a href=\"forum.html\">Les forum</a></p>");
 out.println(" <h3>Dine grupper:</h3>");
 out.println(" <a href=\"gruppe.html\">Gruppenavn</a><br>");
 out.println("  <a href=\"gruppe.html\">Gruppenavn2</a><br>");
 out.println("  <a href=\"gruppe.html\">Gruppenavn3</a>");
 out.println(" </body>");
 out.println(" </html>");
        }
       }

}
